﻿
Imports osi.root.constants

<global_init(global_init_level.log_and_counter_services)>
Public Module _error_counter
    Private ReadOnly CRITICAL_ERROR_COUNTER As Int64
    Private ReadOnly EXCLAMATION_ERROR_COUNTER As Int64
    Private ReadOnly SYSTEM_ERROR_COUNTER As Int64
    Private ReadOnly OTHER_ERROR_COUNTER As Int64

    Sub New()
        CRITICAL_ERROR_COUNTER = counter.register_counter("CRITICAL_ERROR_COUNTER")
        EXCLAMATION_ERROR_COUNTER = counter.register_counter("EXCLAMATION_ERROR_COUNTER")
        SYSTEM_ERROR_COUNTER = counter.register_counter("SYSTEM_ERROR_COUNTER")
        OTHER_ERROR_COUNTER = counter.register_counter("OTHER_ERROR_COUNTER")

        AddHandler error_handle_event.raise_error, AddressOf update_counter
    End Sub

    Private Sub update_counter(ByVal err_type As error_type, ByVal errtype_char As Char, ByVal msg As String)
        If err_type = error_type.critical Then
            counter.increase(CRITICAL_ERROR_COUNTER)
        ElseIf err_type = error_type.exclamation Then
            counter.increase(EXCLAMATION_ERROR_COUNTER)
        ElseIf err_type = error_type.other Then
            counter.increase(OTHER_ERROR_COUNTER)
        ElseIf err_type = error_type.system Then
            counter.increase(SYSTEM_ERROR_COUNTER)
        End If
    End Sub

    Private Sub init()
    End Sub
End Module
